package com.lwz.eduservice.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lwz.eduservice.entity.EduCourse;
import com.lwz.eduservice.entity.EduTeacher;
import com.lwz.eduservice.service.EduCourseService;
import com.lwz.eduservice.service.EduTeacherService;
import com.lwz.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Lw中
 * @date 2020/11/16 17:06
 */

@RestController
@CrossOrigin
@RequestMapping("/eduservice/indexFront")
public class IndexFrontController {

    @Autowired
    EduCourseService eduCourseService;

    @Autowired
    EduTeacherService eduTeacherService;

    /**
     *
     * @return
     */
    @GetMapping("/index")
    public R index() {
        // 通过id排序查询前四名讲师
        QueryWrapper<EduTeacher> wrapper = new QueryWrapper<>();
        wrapper.orderByDesc("id");
        wrapper.last("limit 4");
        List<EduTeacher> teacherList = eduTeacherService.list(wrapper);
        // 通过课程查看次数查询热度前八的课程
        QueryWrapper<EduCourse> wrapper1 = new QueryWrapper<>();
        wrapper1.orderByDesc("view_count");
        wrapper1.last("limit 8");
        List<EduCourse> courseList = eduCourseService.list(wrapper1);
        return R.ok().data("courseList", courseList).data("teacherList", teacherList);
    }


}
